FruiteItem = import("app.scenes.FruitItem")

local PlayScene = class("PlayScene", function()
    return display.newScene("PlayScene")
end)

function PlayScene:ctor()
    self.highScore = 0
    self.stage = 1
    self.target = 123
    self.curSorce = 0

    -- 水平方向水果数量
    self.xCount = 8
    -- 垂直方向水果数量
    self.yCount = 8
    self.fruitGap = 0
    math.newrandomseed()

    -- 1 号水果的位置初始化
    self.matrixLBX = (display.width - FruiteItem.getWidth() * self.xCount - (self.yCount - 1) * self.fruitGap) / 2
    self.matrixLBY = (display.height - FruiteItem.getWidth() * self.yCount - (self.xCount - 1) * self.fruitGap) / 2 - 30

    -- 转场动画结束
    -- 这样看 所有的事件绑定都是一样的方法
    self:addNodeEventListener(cc.NODE_EVENT, function(event)
        if event.name == "enterTransitionFinish" then
            self:initMatrix()
        end
    end)

    self:initUI()
end

function PlayScene:initMatrix()
end

function PlayScene:initUI()
    -- 主场景加载一次资源 可以在其他场景复用 ???
    display.newSprite('#high_score.png')
        :align(display.LEFT_CENTER, display.left + 15, display.top - 30)
        :addTo(self)

    display.newSprite('#highscore_part.png')
        :align(display.LEFT_CENTER, display.cx + 10, display.top - 26)
        :addTo(self)

    self.highScoreLabel = cc.ui.UILabel.new({
        UILabelType = 1,
        text = tostring(self.highScore),
        font = 'font/earth38.fnt',
    })
        -- 可以同时设置锚点以及座标
        -- 锚点可以理解为相对与父节点进行绝对定位，同时也是旋转的中心点
        :align(display.CENTER, display.cx + 105, display.top - 24)
        :addTo(self)
end

function PlayScene:onEnter()
end

function PlayScene:onExit()
end

return PlayScene

